<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class User_like extends CI_Model {

	const DB_SHICAI = 'shicai_new';
	const DB_LIKE = 'shicai_like';	

	function __construct()
	{
		parent::__construct();
	
	}

	//根据用户ID， 查询用户喜欢的食材
	function get_like_by_uid($user_id, $offset = 0, $limit = 6)
	{
		$this->db->select("".self::DB_SHICAI.".id, ".self::DB_SHICAI.".title");
		$this->db->join(self::DB_LIKE, "".self::DB_LIKE.".shicai_id = ".self::DB_SHICAI.".id");
		$this->db->where("uid", $user_id);
		return $this->db->get(self::DB_SHICAI, $limit, $offset);
	}

	//根据用户ID，食材ID 查询 是否为空
	function get_shicai_like($shicai_id, $user_id)
	{
		$array = array(
			'uid' => intval($user_id),
			'shicai_id' => intval($shicai_id)
		);
		return  $this->db->get_where(self::DB_LIKE, $array)->num_rows();
	}
	//插入我喜欢的食材
	function add_shicai_like($shicai_id, $user_id)
	{
		$array = array(
			'uid' 		=> intval($user_id),
			'shicai_id' => intval($shicai_id)
		);

		return $this->db->insert(self::DB_LIKE, $array);
	}
	//删除我喜欢的食材
	function del_shicai_like($shicai_id, $user_id)
	{
		$array = array(
			'uid' 		=> intval($user_id),
			'shicai_id' => intval($shicai_id)
		);
		return $this->db->delete(self::DB_LIKE, $array);
	}
	function del_user_id($user_id)
	{
		$array = array(
			'uid' 		=> intval($user_id)
		);
		return $this->db->delete(self::DB_LIKE, $array);
	}
}

/* End of file user_like.php */
/* Location: ./application/models/user_like.php */